// 根据角色动态生成路由
import { defineFakeRoute } from "vite-plugin-fake-server/client";

export default defineFakeRoute([
  {
    url: "/login",
    method: "post",
    response: ({ body }) => {
      if (!body.username || !body.password) {
        return {
          code: -1,
          msg: "用户名或密码不能为空",
          data: null
        };
      }
      if (body.username === "admin") {
        return {
          code: 0,
          msg: "登录成功",
          data: {
            username: "admin",
            nickname: "admin",
            avatar: "https://avatars.githubusercontent.com/u/44761321",
            roles: ["admin"],
            token: "eyJhbGciOiJIUzUxMiJ9.admin",
            refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh",
            expires: "2024/10/30 00:00:00",
            accountId: 1
          }
        };
      } else {
        return {
          code: 0,
          msg: "登录成功",
          data: {
            username: "common",
            nickname: "common",
            avatar: "https://avatars.githubusercontent.com/u/44761321",
            roles: ["common"],
            token: "eyJhbGciOiJIUzUxMiJ9.common",
            refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh",
            expires: "2024/10/30 00:00:00",
            accountId: 2
          }
        };
      }
    }
  }
]);
